#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstring>
#define endl "\n"
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

	long long a,a1,b,b1,n,num=1,p=998244352;
	cin>>a>>n;
	while(n--)
	{
		cin>>b;
		if(ss[b]!=0)
        {
            cout<<ss[b]<<" ";
            continue;
        }
		num=1,a1=a,b1=b;
		while(b1)
		{
			if(b1&1)
			{
				num=num*a1%p;
			}
			b1>>=1;
			a1=a1*a1%p;
		}
		cout<<num<<" ";
		ss[b]=num;
	}
	cout<<endl;
	return 0;
}
